#include <iostream>
#include "Slave.h"
#include <mpi.h>

using namespace std;

class MyJob : Job{
	public:	
		void Run(char *buffer){
			cout << "MyJob here" << endl;
			cout << sizeof(buffer) << endl;
		}			
};

int main(int argc, char *argv[]){
	int pool_size, my_rank;

	MPI_Init(&argc, &argv);
	MPI_Comm_size(MPI_COMM_WORLD, &pool_size);
	MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
	
	printf("Initialized node: %d of %d\n", my_rank, pool_size);

	// poki co, testowe wyslanie 
	if (my_rank==0){
		MPI_Request request;
		MPI_Status status;
		
		char jobBuffer[1024];
		int tag = 5;
		
		for(int i=1; i<pool_size; i++){
			MPI_Isend (jobBuffer, sizeof(jobBuffer), MPI_CHAR,
					   1, tag, MPI_COMM_WORLD, &request);
			MPI_Wait (&request, &status);
		}
	}
	
	// Slaves
	if (my_rank!=0){
		MyJob *myjob = new MyJob();		
		Slave *slave = new Slave(my_rank, pool_size, 0, 1024, (Job*)myjob);
	}		
		
	printf("End main()\n");
}
